#! /bin/bash

sudo rm -rf ../output/*
gcc -m32 -I ../device/inc -I ../lib/kernel/inc -I ../kernel/inc -c ../device/src/timer.c -o ../output/timer.o -march=i686 -fno-stack-protector
gcc -m32 -I ../device/inc -I ../lib/kernel/inc -I ../kernel/inc -c ../kernel/src/interrupt.c -o ../output/interrupt.o -march=i686 -fno-stack-protector
gcc -m32 -I ../device/inc -I ../lib/kernel/inc -I ../kernel/inc -c ../kernel/src/init.c -o ../output/init.o -march=i686 -fno-stack-protector
gcc -m32 -I ../device/inc -I ../lib/kernel/inc -I ../kernel/inc -c ../kernel/src/main.c -o ../output/main.o -march=i686 -fno-stack-protector
nasm -f elf ../lib/kernel/src/print.S -o ../output/print.o
nasm -f elf ../kernel/src/kernel.S -o ../output/kernel.o
ld -m elf_i386 -Ttext=0xc0001500 -e main  -o ../output/kernel.bin ../output/main.o  ../output/init.o ../output/interrupt.o ../output/print.o ../output/kernel.o ../output/timer.o
sudo dd if=../output/kernel.bin of=/home/jianglin/Software/bochs-2.6.2/hd60M.img bs=512 seek=9 count=200 conv=notrunc
if [ "$1" != "n" ]
    then
    sudo /home/jianglin/Software/bochs-2.6.2/bin/bochs -f /home/jianglin/Software/bochs-2.6.2/bin/bochsrc.disk
fi